Skip to content

Add SQLiteEngine.moveTable to move unsent rows from another database file - #9

Merged
tetujin merged 1 commit into
mainfrom
feature/move-table
Nov 19, 2026
Merged

tetujin merged 1 commit into
mainfrom
feature/move-table

Conversation

@tetujin

@tetujin tetujin commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a sensor's default dbPath changes, the rows still waiting for upload in the old file would never be sent. The first user of this is gyroscope. Up to 1.6.2 it stored its rows in the shared aware.sqlite, although its README said aware_gyroscope.

SQLiteEngine.moveTable(_:fromDatabaseAt:) does the following:

  • It copies only the rows above the old database's sync marker. Rows that were already uploaded stay out.
  • The rows keep their order. They get new IDs after the rows the table already has, so the next sync sends them.
  • It drops the old table and removes the old marker.
  • A marker from 1.6.1 or earlier is taken over by the old database first. Otherwise the new database could take it over and skip the moved rows, whose IDs start from 1.
  • The copy and the drop are one transaction in the new database. If the app stops before the old file is updated, the next call copies the rows again. The server may then receive duplicates, but no row is lost.
  • It does nothing when the old file or the table does not exist, so it is safe to call at every launch.

The README section "Sync markers" describes it.

Tests

MoveTableTests adds four tests:

  • Only rows that were not uploaded move, in order and with the same values. The old table and the old marker are removed, and a second call moves nothing.
  • Moved rows come after the new database's marker.
  • A marker from 1.6.1 or earlier does not make the new database skip moved rows.
  • Nothing happens when there is no old file, no old table, or the old path is the same database.

All 109 core tests pass.

Release note: this needs a tag (1.7.1). The gyroscope PR depends on it.

🤖 Generated with Claude Code

…file

When a sensor's default dbPath changes, rows still waiting for upload in the
old file would never be sent. moveTable(_:fromDatabaseAt:) copies the rows
above the old database's sync marker, in order, into this database (after the
rows already there), drops the old table and removes its marker. A marker from
1.6.1 or earlier is taken over by the old database first, so the new database
never skips moved rows. Copy and drop are one transaction here; if the app
stops before the old file is updated, the next call copies again (possible
duplicates, no loss). It does nothing when there is nothing to move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tetujin
tetujin merged commit e3cd943 into main Nov 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant